CFLAGS=-g -Wall
#CC=/home/sainw/esd/tplink/trunk/staging_dir/toolchain-mips_r2_gcc-linaro_uClibc-0.9.32/bin/mips-openwrt-linux-gcc
CC=gcc
#AR=/home/sainw/esd/tplink/trunk/staging_dir/toolchain-mips_r2_gcc-linaro_uClibc-0.9.32/bin/mips-openwrt-linux-ar
AR=ar
RANLIB=ranlib
LIBS=-L./ -lcgic

all: libcgic.a cgictest.cgi capture cgi-get-file.cgi cgi-upload-file.cgi cgi-op.cgi

install: libcgic.a
	cp libcgic.a /usr/local/lib
	cp cgic.h file.h /usr/local/include
	@echo libcgic.a is in /usr/local/lib. cgic.h is in /usr/local/include.

libcgic.a: cgic.o cgic.h file.h
	rm -f libcgic.a
	$(AR) rc libcgic.a cgic.o
	$(RANLIB) libcgic.a

#mingw32 and cygwin users: replace .cgi with .exe

cgictest.cgi: cgictest.o libcgic.a
	$(CC) cgictest.o -o cgictest.cgi ${LIBS}

capture: capture.o libcgic.a
	$(CC) capture.o -o capture ${LIBS}

cgi-get-file.cgi: cgi-get-file.o libcgic.a file.o
	$(CC) $(CFLAGS) cgi-get-file.o -o cgi-get-file.cgi file.o ${LIBS}

cgi-upload-file.cgi: cgi-upload-file.o libcgic.a file.o
	$(CC) $(CFLAGS) cgi-upload-file.o -o cgi-upload-file.cgi file.o ${LIBS}

cgi-op.cgi: cgi-op.o libcgic.a file.o
	$(CC) $(CFLAGS) cgi-op.o -o cgi-op.cgi file.o ${LIBS}

file.o: file.h file.c 
	$(CC) $(CFLAGS) file.c -c -o file.o
clean:
	rm -f *.o *.a cgictest.cgi capture cgi-get-file.cgi cgi-upload-file.cgi cgi-op.cgi file.o 

